package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.domain.SysBattery;
import com.zhentao.domain.SysPlan;
import com.zhentao.domain.SysScarify;
import com.zhentao.domain.vo.Result;
import com.zhentao.service.SysPlanService;
import com.zhentao.service.SysScarifyService;
import com.zhentao.mapper.SysScarifyMapper;
import com.zhentao.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

/**
* @author 86186
* @description 针对表【sys_scarify】的数据库操作Service实现
* @createDate 2024-09-09 09:31:27
*/
@Service
public class SysScarifyServiceImpl extends ServiceImpl<SysScarifyMapper, SysScarify>
    implements SysScarifyService{
    @Autowired
    private UserUtils utils;
    @Autowired
    private SysPlanService service;


    @Override
    public Result addData(SysBattery sysBattery) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, new Date().getYear());
        calendar.set(Calendar.MONTH, new Date().getMonth()+2);
        calendar.set(Calendar.DAY_OF_MONTH, new Date().getDay());
        Date time = calendar.getTime();
        SysPlan sysPlan = new SysPlan();
        sysPlan.setUid(utils.GetUserId());
        sysPlan.setBid(sysBattery.getId());
        sysPlan.setPtypeId(1);
        sysPlan.setStartTime(new Date());
        sysPlan.setEndTime(time);
        sysPlan.setPrice(sysBattery.getBatteryPrice());
        service.save(sysPlan);
        SysScarify sysScarify = new SysScarify();
        sysScarify.setUid(utils.GetUserId());
        sysScarify.setMoney(sysBattery.getBatteryPrice());
        sysScarify.setMoneyStatus(1);
        sysScarify.setStatus(2);
        sysScarify.setCreateTime(new Date());
        return this.save(sysScarify) ? Result.build(null,200,"添加成功") : Result.build(null,500,"添加失败");
    }
}




